﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QLPM.DTO;

namespace QLPM.DAO
{
    public class ChiTietKhamBenhDAO
    {
        DataProvider provider;

        public ChiTietKhamBenhDAO()
        {
            provider = new DataProvider();
        }

        public List<ChiTietKhamBenh> LayCTKB(int maKhamBenh)
        {
            String sql = String.Format("select * from CHITIETKHAMBENH where MaKhamBenh = {0}", maKhamBenh);
            provider = new DataProvider("CHITIETKHAMBENH", sql);
            DataTable dt = provider;
            List<ChiTietKhamBenh> ds = new List<ChiTietKhamBenh>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                ChiTietKhamBenh ctkb = new ChiTietKhamBenh();
                ctkb.MaChiTietKhamBenh = Convert.ToInt32(dt.Rows[i]["MaChiTietKhamBenh"].ToString());
                ctkb.MaKhamBenh = Convert.ToInt32(dt.Rows[i]["MaKhamBenh"].ToString());
                ctkb.MaThuoc = Convert.ToInt32(dt.Rows[i]["MaThuoc"].ToString());
                ctkb.MaDonVi = Convert.ToInt32(dt.Rows[i]["MaDonVi"].ToString());
                ctkb.SoLuong = Convert.ToInt32(dt.Rows[i]["SoLuong"].ToString());
                ctkb.MaCachDung = Convert.ToInt32(dt.Rows[i]["MaCachDung"].ToString());
                ds.Add(ctkb);
            }
            return ds;
        }

        public int ThemChiTietKhamBenh(ChiTietKhamBenh ctkb)
        {
            string sql = String.Format("insert into CHITIETKHAMBENH(MaKhamBenh,MaThuoc,MaDonVi,SoLuong,MaCachDung) values({0},{1},{2},{3},{4})", ctkb.MaKhamBenh, ctkb.MaThuoc, ctkb.MaDonVi, ctkb.SoLuong, ctkb.MaCachDung);
            return provider.Excute_Non_Query(sql);
        }
    }
}
